/*
	File:		BaseGun.h
	Author:		Ben Feldmann
	Purpose:	Class for managing base ranged weapon
*/

#include "BaseGun.h"
#include "MessageSystem.h"
#include "CreateProjectileMessage.h"                          
#include "GamePlayState.h"
#include "ObjectManager.h"
//#include "Player.h"

#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_XAudio2.h"


BaseGun::BaseGun(Player* owner)
{
	SetWidth(32);
	SetHeight(32);
	SetTextureID(CSGD_TextureManager::GetInstance()->LoadTexture(_T("Graphics/laserGun.png")));
	SetOwner(owner);
	SetX(owner->GetX() + owner->GetWidth());
	SetY(owner->GetY());
	ObjectManager::GetInstance()->AddObject(this);
	Release();
	type = OBJ_WEAPON;
	rangedType = RW_BASE;

	shotTimer = 0.0f;
	cooldownTimer = 0.0f;
	attackReady = false;
	specialReady = false;
	ROF = 0.3f;
	cooldownSeconds = 10.0f;
	energyCost = 15;
	priceScrap = 0;
	priceCircuit = 0;

	//float cooldownTimer;
	//float shotTimer;
	//float cooldownSeconds;
	//float ROF;
	//bool attackReady;
	//bool specialReady;
	//float energyCost;

	//laserShot = CSGD_XAudio2::GetInstance()->SFXLoadSound(_T("Sound/Ranged Weapons/laserShot.wav"));

	emitter = nullptr;//Emitter::LoadEmitter("Emitters/laserShot.xml");

}

BaseGun::~BaseGun()
{
	if(GetTextureID() != -1 )
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(GetTextureID());
		SetTextureID(-1);
	}
	//if(laserShot != -1)
	//{
	//	CSGD_XAudio2::GetInstance()->SFXStopSound(laserShot);
	//	CSGD_XAudio2::GetInstance()->SFXUnloadSound(laserShot);
	//	laserShot = -1;
	//}

	//emitter->Shutdown();

	ObjectManager::GetInstance()->RemoveObject(this);
}

bool BaseGun::CheckCollision(IEntity* base) 
{
	return false;
}

void BaseGun::Attack() 
{
	if(GetOwner()->GetClock() == false)
	{
		CreateProjectileMessage* msg = new CreateProjectileMessage(BASIC, this);
		MessageSystem::GetInstance()->SendMsg(msg);
		msg = nullptr;
		//CSGD_XAudio2::GetInstance()->SFXPlaySound(laserShot);
		//emitter->Burst();
	}
	else if(GetOwner()->GetClock() == true)
	{
		CreateProjectileMessage* msg = new CreateProjectileMessage(BASIC_CLOCKED, this);
		MessageSystem::GetInstance()->SendMsg(msg);
		msg = nullptr;
		//CSGD_XAudio2::GetInstance()->SFXPlaySound(laserShot);
		//emitter->Burst();
	}

	attackReady = false;
	shotTimer = 0;
}

void BaseGun::SpecialAttack() 
{

}

void BaseGun::Render()
{
	SetX(player->GetX() + player->GetWidth());
	SetY(player->GetY());

	//emitter->SetPosition(GetX(),GetY());
	//if(emitter->IsBursting())
	//	emitter->Render();

	SetDirection(GetOwner()->GetDirection());
	RECT image = {};

	switch(GetDirection())
	{
	case 3:
		{
			image.top = 6;
			image.bottom = 11;
			image.left = 0;
			image.right = 3;
			SetWidth(3);
			SetHeight(5);
			SetX(player->GetX() + 35);
			SetY(player->GetY() + 30);
			
		}
		break;

	case 0:
		{
			image.top = 0;
			image.bottom = 5;
			image.left = 0;
			image.right = 13;
			SetWidth(13);
			SetHeight(5);
			SetX(player->GetX() + 10);
			SetY(player->GetY() + 30);
		}
		break;

	case 2:
		{
			image.top = 6;
			image.bottom = 11;
			image.left = 4;
			image.right = 7;
			SetWidth(3);
			SetHeight(5);
			SetX(player->GetX() + 10);
			SetY(player->GetY() + 35);
		}
		break;
	}


	if(GetOwner()->GetCurWeapon() == 2)
	{
		if(GetTextureID() != -1)
		{
			CSGD_TextureManager::GetInstance()->Draw(GetTextureID(), int(GetX() - GamePlayState::GetInstance()->GetCamX()),
				int(GetY() - GamePlayState::GetInstance()->GetCamY()), 2.0f, 2.0f, &image);
		}
	}
}
